﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using JMT.Data;
using System.Windows.Media.Imaging;
using JMT.Res;

namespace JMT.Controls
{
    public class JTreeNode : TreeViewItem
    {
        public StackPanel _panel;
        public Image _ctlIcon;
        public TextBlock _ctlBlock;

        public JModel JModel { get; private set; }

        public JTreeNode(JModel jModel)
        {
            JModel = jModel;

            _panel = new StackPanel();
            _panel.Orientation = System.Windows.Controls.Orientation.Horizontal;

            _ctlIcon = new Image();
            _ctlIcon.Width = 16;
            _ctlIcon.Height = 16;
            string url = JRes.GetIconPath(jModel);
            if (!string.IsNullOrEmpty(url))
            {
                _ctlIcon.Source = new BitmapImage(new Uri(url, UriKind.RelativeOrAbsolute));
            }

            _ctlBlock = new TextBlock();
            _ctlBlock.SetBinding(TextBlock.TextProperty, "Name");
            _ctlBlock.DataContext = jModel;

            _panel.Children.Add(_ctlIcon);
            _panel.Children.Add(_ctlBlock);
            this.Header = _panel;
            _ctlBlock.Tag = this;
            this.DataContext = jModel;
        }
    }
}
